/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package nl.tomcee.dashboard;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.io.File;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.KeyStroke;
import se.datadosen.jalbum.JAlbumPlugin;
import se.datadosen.jalbum.PluginContext;

/**
 *
 * @version
 * @author Tom
 */
public class DashboardAsPlugin implements JAlbumPlugin {

    private PluginContext context;

    public void init(PluginContext pc) {
        this.context = pc;
        JMenuItem mi = new JMenuItem("Dashboard");
        mi.setAccelerator(KeyStroke.getKeyStroke(
                KeyEvent.VK_D, ActionEvent.ALT_MASK));
        mi.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {

                try {
                    File f = new File(context.getJAlbumContext().getFrame().projectChooser.getSelectedFile().getAbsolutePath());
                    if (f.exists()) {
                        new Dashboard().setVisible(true);
                    }
                } catch (java.lang.NullPointerException ex) {
                    JOptionPane.showMessageDialog(null, "no album project selected!",
                            "Dashboard", JOptionPane.WARNING_MESSAGE);
                }
            }
        });
        context.addToolsMenuItem(mi);
    }

    public boolean onExit() {
        return true;
    }
}
